Domaca uloha1A
#include <iostream>
using namespace std;
float derivaciaL(float** body, int i) {
float h = body[1][0] - body[0][0];
float x0 = body[0][1];
float x1 = body[1][1];
float x2 = body[2][1];
float result = (1 / (2 * h)) * (-3 * x0 + 4 * x1 - x2);
return result;
}
int main() {
int n;
cin >> n;
float** pole = new float*[n];
for (int i = 0; i < n; i++) {
pole[i] = new float[2];
cin >> pole[i][0] >> pole[i][1];
}
char T;
cin >> T;
if (T == 'L') {
float result = derivaciaL(pole, n);
cout << result << endl;
}
for (int i = 0; i < n; i++)
delete[] pole[i];
delete[] pole;
}
Domaca uloha2A
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct TStudent {
string name;
string surname;
string znamka;
int rodnecislo;
};
int rok(int rc) {
int r = (rc / 10000);
if (r < 12) return r + 2000;
else return r + 1900;
}
int PorovnajStudentov(TStudent *s1, TStudent *s2) {
if (s1->surname < s2->surname) return 1;
if (s1->surname > s2->surname) return 0;
if (s1->name < s2->name) return 1;
if (s1->name > s2->name) return 0;
int r1 = rok(s1->rodnecislo);
int r2 = rok(s2->rodnecislo);
if (r1 < r2) return 1;
if (r1 > r2) return 0;
return 0;
}
void InsertionSort(TStudent **pole, int pocet) {
int i, j;
TStudent* tmp;
for (i = 1; i < pocet; i++) {
for (j = i, tmp = pole[i]; (j > 0) && PorovnajStudentov(tmp, pole[j - 1]); j--)
pole[j] = pole[j - 1];
pole[j] = tmp;
}
}
int JeZena(int c) {
return (c % 10000 > 5000);
}
void VypisDatum(int c) {
cout << c % 100 << ". " << (c / 100) % 50 << ". " << rok(c);
}
void vypis_studenta(TStudent *s) {
cout << s->surname << " " << s->name << " ";
cout << "(" << s->znamka << ")" << " ";
cout << "rod. c. " << (s->rodnecislo >= 100000 ? "" : "0") << s->rodnecislo << " ";
if (JeZena(s->rodnecislo))
cout << "zena, narodena" << " ";
else
cout << "muz, narodeny" << " ";
VypisDatum(s->rodnecislo);
cout << endl;
}
void vypis_studentov(TStudent **st, int poc) {
for (int i = 0; i < poc; i++)
vypis_studenta(st[i]);
}
int main()
{
TStudent** studenti = new TStudent*[100];
string n, s, z;
int r;
int count = 0;
ifstream in;
in.open("studenti.txt");
if (!in)
{
cout << "Subor sa nepodarilo otvorit";
return 0;
}
for (; in >> n >> s >> z >> r; count++) {
studenti[count] = new TStudent();
studenti[count]->name = n;
studenti[count]->surname = s;
studenti[count]->znamka = z;
studenti[count]->rodnecislo = r;
}
cout << " neusporiadany zoznam " << count << " studentov zo suboru 'studenti.txt'" << endl;
vypis_studentov(studenti, count);
InsertionSort(studenti, count);
cout << endl;
cout << "USPORIADANY zozn. " << count << " studentov zo sub 'studenti.txt' funkciou 'InsertionSort'" << endl;
vypis_studentov(studenti, count);
cout << endl;
cout << "----------------------------------------------" << endl;
cout << "vlozte rok narodenia hladanych studentov: ";
int hladani;
cin >> hladani;
if (hladani >= 1912 && hladani <= 2011) {
cout << "vlozte znamku, ktoru maju mat hladani studenti: ";
string znamka;
cin >> znamka;
cout << endl;
TStudent** najdeni = new TStudent*[count];
int pocetNajdenych = 0;
for (int i = 0; i < count; i++) {
if (rok(studenti[i]->rodnecislo) == hladani && studenti[i]->znamka == znamka) {
najdeni[pocetNajdenych++] = studenti[i];
}
}
cout << "pocet a zoznam studentov narodenych v roku " << hladani << " so znamkou " << znamka << ": " << pocetNajdenych << endl;
vypis_studentov(najdeni, pocetNajdenych);
delete[] najdeni;
}
for (int i = 0; i < count; i++)
delete studenti[i];
delete[] studenti;
}
Domaca uloha3A
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class FirmaAutobazar {
private:
string nazovFirmy;
string pravnaForma;
string sidloFirmy;
long ICO;
long long DIC;
public:
FirmaAutobazar(string Name, string Form, string Place, long ICO1, long long DIC1);
string getNazovFirmy() { return nazovFirmy; };
string getPravnaForma() { return pravnaForma; };
string getSidloFirmy() { return sidloFirmy; };
long getICO() {return ICO; };
long long getDIC() { return DIC; };
void setNazovFirmy(string Name) { nazovFirmy = Name; };
void setPravnaFirma(string Form) { pravnaForma = Form; };
void setSidloFirmy(string Place) { sidloFirmy = Place; };
void setICO(long ICO1) { ICO = ICO1; };
void setDIC(long long DIC1) { DIC = DIC1; };
};
FirmaAutobazar::FirmaAutobazar(string Name, string Form, string Place, long ICO1, long long DIC1) {
nazovFirmy = Name;
pravnaForma = Form;
sidloFirmy = Place;
ICO = ICO1;
DIC = DIC1;
}
class Automobil : private FirmaAutobazar {
private:
string znacka;
int rok;
int predajneCislo;
long predajnaCena;
public:
Automobil(string Name, string Form, string Place, long ICO1, long long DIC1, string Brand, int Year, int Number, long Price);
string getZnacka() { return znacka; };
int getRok() { return rok; };
int getPredajneCislo() { return predajneCislo; };
long getPredajnaCena() { return predajnaCena; };
void setZnacka(string Brand) { znacka = Brand; };
void setRok(int Year) { rok = Year; };
void setPredajneCislo(int Number) { predajneCislo = Number; };
void setPredajnaCena(long Price) { predajnaCena = Price; };
friend ostream& operator<<(ostream& os, Automobil& t);
};
Automobil::Automobil(string Name, string Form, string Place, long ICO1, long long DIC1, string Brand, int Year, int Number, long Price) :
FirmaAutobazar(Name, Form, Place, ICO1, DIC1) {
znacka = Brand;
rok = Year;
predajneCislo = Number;
predajnaCena = Price;
}
ostream& operator<<(ostream& os, Automobil& t) {
os << "nazov firmy prevadzk. autobazar s predavanym autom : " << t.getNazovFirmy() << endl;
os << "pravna forma fy. prevadzk. autobazar s predavanym autom : " << t.getPravnaForma() << endl;
os << "sidlo firmy prevadzk. autobazar s predavanym autom : " << t.getSidloFirmy() << endl;
os << "ICO firmy prevadzk. autobazar s predavanym autom : " << t.getICO() << endl;
os << "znacka a typ auta : " << t.getZnacka() << endl;
os << "rok vyroby auta : " << t.getRok() << endl;
os << "predajne cislo auta : " << t.getPredajneCislo() << endl;
os << "predajna cena auta [Eur] : " << t.getPredajnaCena() << endl;
return os;
}
int main() {
cout << "kolko automobilov chcete vkladat do programu? ";
int pocet;
cin >> pocet;
cout << "-----------------------------------------------" << endl;
Automobil** pole = new Automobil*[pocet];
Automobil statik = Automobil("Happy_Autobazar", "s.r.o.", "Trnava", 19865789, 2586578521, "Ford_Mondeo", 2010, 589742, 5230);
string Name;
string Form;
string Place;
long ICO1;
long long DIC1;
string Brand;
int Year;
int Number;
long Price;
for (int i = 0; i < pocet; i++) {
cout << "vlozte nazov firmy prevadzk. autobazar s " << i + 1 << ". predavanym autom : ";
cin >> Name;
cout << "vlozte pravnu formu fy. prevadzk. autobazar s " << i + 1 << ". predavanym autom : ";
cin >> Form;
cout << "vlozte sidlo firmy prevadzk. autobazar s " << i + 1 << ". predavanym autom : ";
cin >> Place;
cout << "vlozte ICO firmy prevadzk. autobazar s " << i + 1 << ". predavanym autom : ";
cin >> ICO1;
cout << "vlozte DIC firmy prevadzk. autobazar s " << i + 1 << ". predavanym autom : ";
cin >> DIC1;
cout << "vlozte znacku a typ " << i + 1 << ". auta : ";
cin >> Brand;
cout << "vlozte rok vyroby " << i + 1 << ". auta : ";
cin >> Year;
cout << "vlozte predajne cislo " << i + 1 << ". auta : ";
cin >> Number;
cout << "vlozte predajnu cenu " << i + 1 << ". auta [Eur] : ";
cin >> Price;
cout << "----------------------------------------------" << endl;
pole[i] = new Automobil(Name, Form, Place, ICO1, DIC1, Brand, Year, Number, Price);
}
cout << "programom vytvoreny a inicializovany objekt pomocou parametrickeho konstruktora triedy 'Automobil'" << endl;
cout << "----------------------------------------------" << endl;
cout << statik << endl;
cout << "hodnoty instan. premennych objektov triedy 'Automobil' (aut). vlozene pouzivatelom programu" << endl;
for (int i = 0; i < pocet; i++) {
cout << "----------------------------------------------" << endl;
cout << (*(pole[i]));
}
cout << "----------------------------------------------" << endl;
long long celkovaSuma = statik.getPredajnaCena();
for (int i = 0; i < pocet; i++)
celkovaSuma += pole[i]->getPredajnaCena();
float priemernaCena = ((float)celkovaSuma) / (pocet + 1);
cout << "celkova predajna cena uvedenych " << pocet + 1 << "-och aut [Eur] : " << celkovaSuma << endl;
cout << "priemerna predajna cena uvedenych " << pocet + 1 << "-och aut [Eur] : " << std::setprecision(1) << std::fixed << priemernaCena << endl;
return 0;
}
B
Domaca uloha ,1B
#include <iostream>
using namespace std;
float derivaciaL(float** body, int i) {
float h = body[1][0] - body[0][0];
float x0 = body[i-1][1];
float x1 = body[i-2][1];
float x2 = body[i-3][1];
float result = (1 / (2 * h)) * (3 * x0 - 4 * x1 + x2);
return result;
}
int main() {
int n;
cin >> n;
float** pole = new float*[n];
for (int i = 0; i < n; i++) {
pole[i] = new float[2];
cin >> pole[i][0] >> pole[i][1];
}
char T; cin >> T;
if (T == 'P') {
float result = derivaciaL(pole, n);
cout.precision(3);
cout << result << endl;
}
for (int i = 0; i < n; i++)
delete[] pole[i];
delete[] pole;
}
Domaca uloha ,2B
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
struct TStudent {
string name;
string surname;
string znamka;
int rodnecislo;
};
int rok(int rc) {
int r = (rc / 10000);
if (r < 12) return r + 2000;
else return r + 1900;
}
int PorovnajStudentov(TStudent *s1, TStudent *s2) {
if (s1->surname < s2->surname) return 1;
if (s1->surname > s2->surname) return 0;
if (s1->name < s2->name) return 1;
if (s1->name > s2->name) return 0;
int r1 = rok(s1->rodnecislo);
int r2 = rok(s2->rodnecislo);
if (r1 < r2) return 1;
if (r1 > r2) return 0;
return 0;
}
void InsertionSort(TStudent **pole, int pocet) {
int i, j;
TStudent* tmp;
for (i = 1; i < pocet; i++) {
for (j = i, tmp = pole[i]; (j > 0) && PorovnajStudentov(tmp, pole[j - 1]); j--)
pole[j] = pole[j - 1];
pole[j] = tmp;
}
}
void SelectionSort(TStudent **pole, int pocet) {
int i, j, min;
for (i = 0; i < pocet - 1; i++) {
min = i;
for (j = i + 1; j < pocet; j++) {
if (PorovnajStudentov(pole[j], pole[min]))
min = j;
}
swap(pole[min], pole[i]);
}
}
int JeZena(int c) {
return (c % 10000 > 5000);
}
void VypisDatum(int c) {
cout << c % 100 << ". " << (c / 100) % 50 << ". " << rok(c);
}
void vypis_studenta(TStudent *s) {
cout << s->surname << " " << s->name << " ";
cout << "(" << s->znamka << ")" << " ";
cout << "rod. c. " << (s->rodnecislo >= 100000 ? "" : "0") << s->rodnecislo << " ";
if (JeZena(s->rodnecislo))
cout << "zena, narodena" << " ";
else
cout << "muz, narodeny" << " ";
VypisDatum(s->rodnecislo);
cout << endl;
}
void vypis_studentov(TStudent **st, int poc) {
for (int i = 0; i < poc; i++)
vypis_studenta(st[i]);
}
int main() {
TStudent** studenti = new TStudent*[100];
string n, s, z;
int r;
int count = 0;
ifstream in;
in.open("studenti.txt");
if (!in)
{
cout << "Subor sa nepodarilo otvorit";
return 0;
}
for (; in >> n >> s >> z >> r; count++) {
studenti[count] = new TStudent();
studenti[count]->name = n;
studenti[count]->surname = s;
studenti[count]->znamka = z;
studenti[count]->rodnecislo = r;
}
cout << " neusporiadany zoznam " << count << " studentov zo suboru 'studenti.txt'" << endl;
vypis_studentov(studenti, count);
SelectionSort(studenti, count);
cout << endl;
cout << "USPORIADANY zozn. " << count << " studentov zo sub 'studenti.txt' funkciou 'InsertionSort'" << endl;
vypis_studentov(studenti, count);
cout << endl;
cout << "----------------------------------------------" << endl;
cout << "vlozte pohlavie hladanych studentov: ";
char pohlavie;
cin >> pohlavie;
if (pohlavie == 'z' || pohlavie == 'm') {
cout << "vlozte znamku, ktoru maju mat hladani studenti: ";
string znamka;
cin >> znamka;
cout << endl;
TStudent** najdeni = new TStudent*[count];
int pocetNajdenych = 0;
for (int i = 0; i < count; i++) {
if (studenti[i]->znamka == znamka) {
if (pohlavie == 'z' && JeZena(studenti[i]->rodnecislo))
najdeni[pocetNajdenych++] = studenti[i];
if (pohlavie == 'm' && !JeZena(studenti[i]->rodnecislo))
najdeni[pocetNajdenych++] = studenti[i];
}
}
cout << "pocet a zoznam studentov s pohlavim '" << pohlavie << "' so znamkou '" << znamka << "': " << pocetNajdenych << endl;
vypis_studentov(najdeni, pocetNajdenych);
delete[] najdeni;
}
for (int i = 0; i < count; i++)
delete studenti[i];
delete[] studenti;
}
Domaca uloha ,3B
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class ZOO {
private:
string nazovFirmy;
string pravnaForma;
long pocetZvierat;
long ICO;
long rozloha;
public:
ZOO(string Name, string Form, long Count, long ICO1, long Area);
string getNazov() { return nazovFirmy; };
string getPravnaForma() { return pravnaForma; };
long getPocetZvierat() { return pocetZvierat; };
long getICO() { return ICO; };
long getRozloha() { return rozloha; };
void setNazov(string Name) { nazovFirmy = Name; };
void setPravnaFirma(string Form) { pravnaForma = Form; };
void setPocetZvierat(long Count) { pocetZvierat = Count; };
void setICO(long ICO1) { ICO = ICO1; };
void setRozloha(long long Area ) { rozloha = Area; };
};
ZOO::ZOO(string Name, string Form, long Count, long ICO1, long Area) {
nazovFirmy = Name;
pravnaForma = Form;
rozloha = Area;
ICO = ICO1;
pocetZvierat = Count;
}
class Zviera : private ZOO {
private:
string nazov;
long cislo;
long vek;
long hodnota;
public:
Zviera(string Name, string Form, long Count, long ICO1, long Area, string Animal, long Number, long Age, long Price);
string getZviera() { return nazov; };
long getCislo() { return cislo; };
long getVek() { return vek; };
long getHodnota() { return hodnota; };
void setZviera(string Animal) { nazov = Animal; };
void setCislo(long Number) { cislo = Number; };
void setVek(long Age) { vek = Age; };
void setHodnota(long Price) { hodnota = Price; };
friend ostream& operator<<(ostream& os, Zviera& t);
};
Zviera::Zviera(string Name, string Form, long Count, long ICO1, long Area, string Animal, long Number, long Age, long Price) :
ZOO(Name, Form, Count, ICO1, Area) {
nazov = Animal;
cislo = Number;
vek = Age;
hodnota = Price;
}
ostream& operator<<(ostream& os, Zviera& t) {
os << "nazov ZOO, kde je zviera umiestnene : " << t.getNazov() << endl;
os << "pravna forma ZOO, kde je zviera umiestnene : " << t.getPravnaForma() << endl;
os << "rozloha ZOO, kde je zviera umiestnene : " << t.getRozloha() << endl;
os << "pocet zvierat v ZOO, kde je zviera umiestnene : " << t.getPocetZvierat() << endl;
os << "zviera : " << t.getZviera() << endl;
os << "cislo zvierata : " << t.getCislo() << endl;
os << "vek zvierata : " << t.getVek() << endl;
os << "spoloc. hodnota zvierata [Eur] : " << t.getHodnota() << endl;
return os;
}
int main() {
cout << "kolko zvierat chcete vkladat do programu? ";
int pocet;
cin >> pocet;
cout << "-----------------------------------------------" << endl;
Zviera** pole = new Zviera*[pocet];
Zviera statik = Zviera("ZOO_Kosice", "verejno_pravna", 19865789, 98, 283, "Slon_africky", 5897421, 15, 22000);
string Name;
string Form;
long Count;
long ICO1;
long Area;
string Animal;
long Number;
long Age;
long Price;
for (int i = 0; i < pocet; i++) {
cout << "vlozte nazov ZOO kde je " << i + 1 << ". zviera : ";
cin >> Name;
cout << "vlozte pravnu formu ZOO kde je " << i + 1 << ". zviera umiestnene : ";
cin >> Form;
cout << "vlozte ICO firmy kde je" << i + 1 << ". zviera umiestnene : ";
cin >> ICO1;
cout << "vlozte rozlohu ZOO kde je " << i + 1 << ". zviera umiestnene : ";
cin >> Area;
cout << "vlozte pocet zvierat v ZOO, kde je " << i + 1 << ". zviera umiestnene : ";
cin >> Count;
cout << "vlozte " << i + 1 << ". zviera : ";
cin >> Animal;
cout << "vlozte cislo " << i + 1 << ". zvierata : ";
cin >> Number;
cout << "vlozte vek " << i + 1 << ". zvierata : ";
cin >> Age;
cout << "vlozte spoloc. hodnotu " << i + 1 << ". zvierata [Eur] : ";
cin >> Price;
cout << "----------------------------------------------" << endl;
pole[i] = new Zviera(Name, Form, ICO1, Area, Count, Animal, Number, Age, Price);
}
cout << "programom vytvoreny a inicializovany objekt pomocou parametrickeho konstruktora triedy 'Zviera'" << endl;
cout << "----------------------------------------------" << endl;
cout << statik << endl;
cout << "hodnoty instan. premennych objektov triedy 'Zviera' (zvierat). vlozene pouzivatelom programu" << endl;
for (int i = 0; i < pocet; i++) {
cout << "----------------------------------------------" << endl;
cout << (*(pole[i]));
}
cout << "----------------------------------------------" << endl;
cout << "vlozte vek, od ktoreho maju byt vyhladane zvierata: ";
long vek;
cin >> vek;
cout << endl << "pocet a zoznam zvierat starsich ako " << vek << " rokov" << endl << endl;
int celkovaSuma = 0;
int pocetNajdenych = 0;
if (statik.getVek() > vek) {
celkovaSuma += statik.getHodnota();
pocetNajdenych++;
cout << statik << endl;
}
for (int i = 0; i < pocet; i++) {
if (pole[i]->getVek() > vek) {
pocetNajdenych++;
celkovaSuma += pole[i]->getHodnota();
cout << (*(pole[i]));
cout << "----------------------------------------------" << endl;
}
}
cout << "celkova spolocenska hodnota najdenych " << pocetNajdenych << " zvierat [Eur] : " << celkovaSuma << endl;
for (int i = 0; i < pocet; i++)
delete pole[i];
delete[] pole;
}